<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>03 while</title>
</head>

<body>


    <script>
        var index = 0;
        while (index < 3) {
            index++;
            console.log('index:', index);
        }

        // //全局变量
        // var a = 10;
        // console.log('a:', window.a);

        // //函数
        // function fn() {
        //     var c = 12; //局部变量
        //     var b = 1 + 5;
        //     console.log('b:', b);
        //     console.log('c:', c);
        // }
        // fn();

        //全局变量

        //计算 1+2+3+4+5+...+98+99+100
        var i = 1;
        var sum = 0;
        while (i <= 100) {
            sum += i;
            i++;
        }
        console.log('sum:', sum);

        //1*2*3*...*99*100
        var c = 1;
        var d = 0;
        while (c <= 100) {
            if (c % 2 != 0) {
                d += c;
            }
            c++;
        }
        console.log('d:', d);

        var q = 0;
        w = (1 + 99) * 50 / 2;
        console.log('w:', w);
    </script>
</body>

</html>